/**
 * /**
 * issue list
 * @type {issue_list}
 */

var action_urls = {
    close:C_URI+'{0}/close'
}

var issue_list = function () {
    var grid_id = 'issue_list';
    var editor =null;
//    var info;
    var toolbar = $('#issue_toolbar').toolbar();
    //全局变量表示是单选issue 还是多选issue （0表示多选）
    var ids_post = null;
    //全局变量表示当前单操作的问题id
    var currentId;

    var fix_editor=null;

    // 判断是否显示列表的checkbox
    var bool_show_checkbox = true;
    /**
     * 选中tab的 cookie名称
     * @type {string}  cookie名称
     */
    var select_tab_cookie_name = 'select_tab_cookie';
    /**
     * 选中b_assign 按钮的cookie名称
     * @type {String}
     */
    var select_assign_cookie_name = 'b_assign_cookie';


    /** tab 标签取值*/
    var tab_value={todo:"todo",done:"done",all:"all",my_issue:"my_issue"};
    /**用于b_assign按钮的变量*/
    var cookie_filter = { me : 'assign_to_me', all: 'all_my_issue' };
    /**用与fix按钮的变量*/
    var fix_value={ fixed:'fixed',all:'f_all' };

    //默认显示全部问题，所以显示fixed按钮      全局变量
    var fix_temp=fix_value.fixed;
    /*操作列按钮列表*/
    var operation_icon=[
        {id:"close",icon_url:"/close.png",description:language.issue.close_text},
        {id:"assign",icon_url:"/assigned.png",description:language.issue.column_3},
        {id:"label",icon_url:"/label.png",description:language.issue.list_toolbar_text.label},
        {id:"priority",icon_url:"/priority.png",description:language.issue.list_toolbar_text.prioperty},
        {id:"milestone",icon_url:"/milestone.png",description:language.issue.milestone_msg},
        {id:"fix",icon_url:"/fix.png",description:language.issue.fix_text},
        {id:"undo",icon_url:"/undo.png",description:language.issue.list_toolbar_text.reopen}
    ];
    /**grid列表显示的所有列定义*/
    var columnsDatascource;
    /**
     * 左边工具条
     * @type {Array} 工具条信息，包含todo等的定义
     */
    var tool_bar_datasource = [
        {key: tab_value.todo, values: [
            {id: "issue_close", text: language.issue.list_toolbar_text.close, icon: "closed", onclick: "issue_list.close('0')", tooltip: language.issue.list_tool_tip_msg.close, disabled: "true"},
            {id: "issue_assign", text: language.issue.list_toolbar_text.assign, icon: "assigned", onclick: "issue_list.team_account()", tooltip: language.issue.list_tool_tip_msg.assign, disabled: "true"},
            {id: "issue_label_change", text: language.issue.list_toolbar_text.label, icon: "label", onclick: "issue_list.label_change_div(0)", tooltip: language.issue.list_tool_tip_msg.label, disabled: "true"},
            {id: "issue_priopity_change", text: language.issue.list_toolbar_text.prioperty, icon: "priority", onclick: "issue_list.priopity_layer(0)", tooltip: language.issue.list_tool_tip_msg.prioperty, disabled: "true"},
           {id: "issue_milestones", text: language.issue.list_toolbar_text.milestones, icon: "milestone", onclick: "issue_list.multiple_milestone()", tooltip: language.issue.list_tool_tip_msg.milestones, disabled: "true"}
        ]},
        {key: tab_value.done, values: [
            {id: "issue_reopen", text: language.issue.list_toolbar_text.reopen, icon: "undo", onclick: "issue_list.reopen_issues(0)", tooltip: language.issue.list_tool_tip_msg.reopen, disabled: "true"}
        ]},
        {key: tab_value.all, values: [
        ]},
        {key: tab_value.my_issue, values: [
        ]}
    ];
    var r_button_datascource = [
                        		{id: cookie_filter.me, text: language.issue.list_toolbar_text.assign_to_me, icon: "assignme", onclick: "issue_list.b_assign_switch()", tooltip: language.issue.list_tool_tip_msg.assign_to_me, disabled: "false"},
                        		{id: cookie_filter.all, text: language.issue.list_toolbar_text.all, icon: "allissues", onclick: "issue_list.b_assign_switch()", tooltip: language.issue.list_tool_tip_msg.all, disabled: "false"},
                                {id: fix_value.fixed, text: language.issue.list_toolbar_text.fixed, icon: "fixed", onclick: "issue_list.b_fix_switch()", tooltip: language.issue.list_tool_tip_msg.fixed, disabled: "false"},
                                {id: fix_value.all, text: language.issue.list_toolbar_text.all_with_fix, icon: "fix_all", onclick: "issue_list.b_fix_switch()", tooltip: language.issue.list_tool_tip_msg.all_with_fixed, disabled: "false"}
                            ];
    var format_str = {
        key_format            : '<a href="'+C_URI+'project/issue/view/{0}/'+project_id+'">{0}</a>', summary_format: '<a href="'+C_URI+'project/issue/view/{0}/'+project_id+'">{1}</a>',
        type_format           : '<a href="'+C_URI+'project/issue/view/{0}/'+project_id+'"><img src="' + js_param.image_url + '/{1}" class="icon" title="{2}" alt="{3}" height="16" width="16" border="0"/></a>',
        priopity_format       : '<a href="'+C_URI+'project/issue/view/{0}/'+project_id+'"><img src="' + js_param.image_url + '/{1}"class="icon"title="{2}" alt="{3}"height="13" width="14" border="0"/>{2}</a> ',
        operation_close_format: '<a href="javascript:;"onclick="issue_list. close({0})"><img src="' + js_param.image_url +operation_icon[0].icon_url+'"title="'+operation_icon[0].description+'"height="16" width="16" border="0"/></a>&nbsp;&nbsp;&nbsp;' +
            '<a href="javascript:;" onclick="issue_list.single_assign({0})"><img src="' + js_param.image_url +operation_icon[1].icon_url+'"title="'+operation_icon[1].description+'"height="16" width="16" border="0"/></a>&nbsp;&nbsp;&nbsp;' +
            '<a href="javascript:;"onclick="issue_list.label_change_div({0})"><img src="' + js_param.image_url +operation_icon[2].icon_url+'"title="'+operation_icon[2].description+'"height="16" width="16" border="0"/></a>&nbsp;&nbsp;&nbsp;' +
            '<a href="javascript:;"onclick="issue_list. priopity_layer({0})"><img src="' + js_param.image_url +operation_icon[3].icon_url+'"title="'+operation_icon[3].description+'"height="16" width="16" border="0"/></a>&nbsp;&nbsp;&nbsp;' +
            '<a href="javascript:;"onclick="issue_list. single_milestone({0})"><img src="' + js_param.image_url +operation_icon[4].icon_url+'"title="'+operation_icon[4].description+'"height="16" width="16" border="0"/></a>&nbsp;&nbsp;&nbsp;' ,
       operation_fix_format:    '<a href="javascript:;"onclick="issue_list. fixed({0})"><img src="' + js_param.image_url +operation_icon[5].icon_url+'"title="'+operation_icon[5].description+'"height="16" width="16" border="0"/></a>&nbsp;&nbsp;&nbsp;',
        operation_space_format: '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
        operation_open_format : '<a href="javascript:;" onclick="issue_list. reopen_issues({0})"><img src="' + js_param.image_url +operation_icon[6].icon_url+'"title="'+operation_icon[6].description+'"height="16" width="16" border="0"/></a>'
    };
    var single_assign_layer_operation = $('#single_assign').layer({singleton: true, width: "150px", height: "200px", title: language.issue.issue_assign_title});
    var close_comment_layer = $("#issue_close_comment_back").layer({title : language.issue.issue_colse_comment,width : "550px",height : "350px",singleton: true});
    var fix_comment_layer = $("#issue_fix_comment_back").layer({title : language.issue.issue_colse_comment,width : "550px",height : "350px",singleton: true});
   var single_milestone_layer_operation =$('#single_milestone').layer({singleton: true, width: "150", height: "200", title:language.issue.issue_milestones_title});
    var cleanup = function () {
        //清理Cookie
        $.cookie(select_tab_cookie_name, null);
        $.cookie(select_assign_cookie_name,null);
        cdms.common.clear_grid_page_cookie(grid_id);
        //清理后，修改瞄点，防止下次无法记住cookie的问题
        window.location.hash = 'local';
    };
    return {
        /**
         * 初始化Tab控件
         */
        init      : function () {
            //是否存在瞄点
            var newClear = window.location.hash;
            if (newClear) {
                var action = newClear.split('#')[1];
                switch (action) {
                    case "todo":
                        cleanup();
                        $.cookie(select_tab_cookie_name,tab_value.todo,{expires:1});  break;
                    case "done":
                        cleanup();
                        $.cookie(select_tab_cookie_name,tab_value.done,{expires:1});   break;
                      case "all":
                        cleanup();
                        $.cookie(select_tab_cookie_name,tab_value.all,{expires:1});    break;
                    default :
                        break;
                }
            }
            var tab = $('#issue_tab').tab();
            tab.event('select', function (item) {
                issue_list.tab_select_evt(item);
            });
            //初始化b_assign的cookie，如果没有b_assign的cookie,默认b_assign为  all
            if(!$.cookie(select_assign_cookie_name)){
                $.cookie(select_assign_cookie_name, cookie_filter.all, { expires: 1 });
            }
            //上次选中的Tab
            var select_tab_name = $.cookie(select_tab_cookie_name);
            var select_tab;
            if (!select_tab_name) {
                //如果以前tab没有选中，则用默认地一个  (第一个)
                select_tab = tab.items(0);
            } else {
                select_tab = tab.getItemById(select_tab_name);
            }
            issue_list.tab_select(select_tab.attr('id'));
            select_tab.attr("selected", "true");

            //toolbar   右边按钮处理
//            issue_list.display_rlitem();
        },
        tab_select_evt: function (tab_item) {
            cdms.common.clear_grid_page_cookie(grid_id);
            var tab_id = tab_item.item.attr('id');
            issue_list.tab_select(tab_id);
        },
        /**
         * 对Tab进行处理，包含数据的渲染
         * @param tab_id tab选项卡ID
         */
        tab_select    : function (tab_id) {
            $('#issue_p_select').attr("value", "");
            //设置工具条
            $.each(tool_bar_datasource, function (idx, val) {
                if (val.key == tab_id) {
                    toolbar.attr("dataSource", [val.values]);
                    return false;
                }
            });
            //初始化label   priopity  div
            var label_div = $('#label_change_div');
            label_div.removeClass();
            var priopity_div = $('#priopity_change_div_list');
            priopity_div.removeClass();
            label_div.hide();
            priopity_div.hide();
            $.cookie(select_tab_cookie_name, tab_id, {expires: 1});
          // toolbar   右边按钮处理
            issue_list.display_rlitem();
           //显示前的  页面显示项目  条件过滤设置
            issue_list.display_filter();
            issue_list.list({tab_id: tab_id, p_id:project_id , m_id:milestone_id,b_assign: $.cookie(select_assign_cookie_name), fix:fix_value.all});
        },

        //显示前的  页面显示项目  条件过滤设置
        display_filter:         function(){
            columnsDatascource=
                [
                    [
                        {title: "T", field: "issuetype", width: "30px", headAlign: 'center', align: 'center',formatter: issue_list.type_formatter,sortfield: "issuetype"},
                        {title: "key", field: "pkey", width: "120px", headAlign: 'left', formatter: issue_list.pkeyFormatter, sortfield: "pkey"},
                        {title: language.issue.column_1, field: "summary", headAlign: 'left',formatter: issue_list.titleFormatter},
                        {title: language.issue.column_6, field: "priopity", width: "60px", headAlign: 'left', align: "left", formatter: issue_list.priopityFormatter,sortfield: "priopity"},
                        {title: language.issue.column_2, field: "reporter", width: "100px", headAlign: 'left'},
                        {title: language.issue.column_3, field: "assigneeName", width: "100px", headAlign: 'left'},
                        {title: language.issue.column_4, field: "created", width: "150px", headAlign: 'left', sortfield: "created"},
                        {title: language.common.operation, field: "operation", width: "190px", align: 'center',formatter: issue_list.operationFormatter}
                    ]
                ];
            bool_show_checkbox=true;
            if($.cookie(select_tab_cookie_name)==tab_value.all||$.cookie(select_tab_cookie_name)==tab_value.my_issue){
                /**设置  columnsDatascource    移除operation列项*/
                columnsDatascource[0].splice(7,1);
                /**设置 checkbox是否显示   false为不显示*/
                bool_show_checkbox=false;
            }
        },

        /**
         * b_assign按钮开关切换
         */
        b_assign_switch: function () {
            //清空 page  cookie
            cdms.common.clear_grid_page_cookie(grid_id);
            $.cookie(select_assign_cookie_name, ($.cookie(select_assign_cookie_name) == cookie_filter.all) ? cookie_filter.me : cookie_filter.all, { expires: 1 });
            //显示之前把相对应的另一个按钮置为  显示所有问题
            fix_temp=fix_value.fixed;
            issue_list.display_rlitem();
            //显示前的  页面显示项目  条件过滤设置

            issue_list.display_filter();
            //修改b_assign  cookie值
            //issue_list.list({tab_id: $.cookie(select_tab_cookie_name),p_id:project_id, b_assign: $.cookie(select_assign_cookie_name),fix:null});
             issue_list.list({tab_id: $.cookie(select_tab_cookie_name), p_id:project_id , m_id:milestone_id,b_assign: $.cookie(select_assign_cookie_name), fix:fix_value.all});
        },
//
        /**
         * fix按钮开关切换
         */
        b_fix_switch:function(){
            //保存现在的fix值，再进行切换
            var fix=fix_temp;
            //开关切换
            fix_temp= (fix_temp==fix_value.fixed?fix_value.all:fix_value.fixed);
            //显示之前把相对应的另一个按钮置为  显示所有问题
            $.cookie(select_assign_cookie_name,cookie_filter.all);
            issue_list.display_rlitem();
            //显示前的  页面显示项目  条件过滤设置
            issue_list.display_filter();
            //issue_list.list({p_id:project_id,fix:fix});
             issue_list.list({tab_id: $.cookie(select_tab_cookie_name), p_id:project_id , m_id:milestone_id,b_assign: $.cookie(select_assign_cookie_name), fix:fix});
        },

        /**
         *  toolbar 右边按钮显示处理
         */
        display_rlitem : function () {
            //如果是  my_issue就不显示右按钮
            if($.cookie(select_tab_cookie_name)!= "my_issue"){
                var b_assign = $.cookie(select_assign_cookie_name);
                toolbar.ritems(0) != null ? toolbar.ritems(0).remove() : null;
                toolbar.insertRight(r_button_datascource[b_assign == cookie_filter.me ? 1 : 0], 0);
                //  为todo时显示fix
                if($.cookie(select_tab_cookie_name)== tab_value.todo){
                    //如果是第一个标签，在右位置1加入按钮。  而且默认是显示全部。
                    toolbar.ritems(1) != null ? toolbar.ritems(1).remove() : null;
                    toolbar.insertRight(r_button_datascource[fix_temp == fix_value.fixed ? 2 : 3], 1);
                }
            }
        },

        /**
         * list show
         */
        list                  : function (params) {
            cdms.common.jart_grid(grid_id, {
                sortField: 'created', url:js_param.issue_list_json_url, idFields: 'id', gridline: 'horizontal', queryParams: params,showCheckBox : bool_show_checkbox,
                columns  : columnsDatascource,
                //选中触发事件
                onCheck  : function () {
                    issue_list.toolbar_disabled_check();
                },
                //更新列表触发事件
                onUpdate  : function () {
                    issue_list.toolbar_disabled_check();
                }
            });
        },
        /**
         * checkRows  disabled操作函数
         */
        toolbar_disabled_check: function () {
            var rows = $('#' + grid_id).grid("checkedRows");
            for (var i = 0; i <toolbar.attr("dataSource")[0].length; i++) {
                toolbar.litems(i).attr('disabled', rows.length == 0);
            }
        },
        pkeyFormatter : function (item) {
            return format_str.key_format.format(item.pkey);
        },
        titleFormatter: function (item) {
            return format_str.summary_format.format(item.pkey, item.summary);
        },
//
        priopityFormatter: function (item) {
            var priopity = {};
            $.each(priopity_list, function (idx, val) {
                if (val.id == item.priopity) {
                    priopity = val;
                    return false;
                }
            });
            return  format_str.priopity_format.format(item.pkey, priopity.iconUrl, priopity.description, priopity.name);
        },
        type_formatter   : function (item) {
            var type = {};
            $.each(type_list, function (idx, val) {
                if (val.id == item.issuetype) {
                    type = val;
                    return false;
                }
            });
            return  format_str.type_format.format(item.pkey, type.icon, type.description, type.pname)
        },

        /**
         * Reopen   one or more issues those been closed
         *
         */
        reopen_issues        : function (id) {
            ids_post=(id==0?cdms.common.grid_select_ids(grid_id):id );
            cdms.common.confirm(language.issue.reopen_tip_msg, function () {
                cdms.common.ajax_get(js_param.open_issue_url + ids_post, issue_list.reload);
                issue_list.toolbar_disabled_check();
            });
        },
        /**
         * format the hyper link of operation
         * @param item     item.issuestatus: 0:打开状态    1：关闭状态   2 ：fixed状态
         * @return {*}
         */
        operationFormatter   : function (item) {
            switch (item.issuestatus) {
                case 1:
                    return   format_str.operation_open_format.format(item.id, item.summary);
                    break;
                case 2:
                    return   format_str.operation_close_format.format(item.id, item.summary, item.reporter, item.priopity, item.pid)+format_str.operation_space_format.format();
                    break;
                case 0 :
                    return format_str.operation_close_format.format(item.id, item.summary, item.reporter, item.priopity, item.pid)+format_str.operation_fix_format.format(item.id);
                    break;
                default : ;
            }
        },
        /**
         * Quick comment when user batch close question
         *
         */
        close_comment_submit : function(){
            var form_msg = $('#close_form_msg');
            form_msg.html("<span class='ajax_processing'>" + language.issue.issue_comment_submit_note + "</span>");
            if (editor.isEmpty()) {
                $.alert(language.issue.issue_comment_empty_msg, language.note.alert_title);
                return false;
            }
            form_msg.show();
            var params = {ids:ids_post,content:editor.html()};
            /**
             * ajax_post 提交回复信息
             * @parma params json格式参数 包含问题id列表和回复信息
             * 成功返回后修改提示信息，关闭弹出层
             */
            cdms.common.ajax_post(js_param.close_comment_submit_url,params,function(json){
                json = eval("("+json+")");
                if (json.type) {
                    issue_list.toolbar_disabled_check();
                     editor.html("");
                    close_comment_layer.close();
                    form_msg.hide();
                    issue_list.reload();
                } else {
                    form_msg.html("<span class='error_msg'>" + json.msg + "</span>");
                    form_msg.show();
                }
            });
        },
        /**
         * 修复问题功能函数                                    alert($("#issue_fix_comment_back").layer().attr("title"));
         * @param id
         */
        fixed :function(id){
               fix_comment_layer.open();
                $("#fix_issue_comment_id").attr("value",id);
                if(fix_editor == null){
                    fix_editor = KindEditor.create('#fix_txt_answner', {
                        themeType            : 'default',
                        resizeType           : 0,
                        urlType              : 'domain',
                        shadowMode           : false,
                        allowPreviewEmoticons: false,
                        allowImageUpload     : true,
                        allowFlashUpload     : false,
                        uploadJson           : js_param.upload_url,
                        afterCreate          : function () {
                            KindEditor.ctrl(this.edit.iframe.get(0).contentWindow.document, 13, function () {
                                $("#fix_txt_answner").parent().submit();
                            });
                        },
                        afterChange          : function () {
                            this.sync();
                        },
                        items                : ['bold', 'italic', 'underline', 'strikethrough', 'removeformat', '|', 'insertorderedlist', 'insertunorderedlist',
                            'forecolor', 'hilitecolor', 'fontname', 'fontsize', '|', 'link', 'unlink', 'image', 'flash', 'quote', '|', 'source', 'about']
                    });
                }
        },

        /**
         * fix 反馈提交
         *
         */
        fix_comment_submit  : function(){
            var form_msg = $('#fix_form_msg');
            form_msg.html("<span class='ajax_processing'>" + language.issue.issue_comment_submit_note + "</span>");

            if (fix_editor.isEmpty()) {
                $.alert(language.issue.issue_comment_empty_msg, language.note.alert_title);
                return false;
            }
            form_msg.show();

            var id=$("#fix_issue_comment_id").attr("value");
            var content=fix_editor.html();
            var params ={"id":id,"content":content};
            cdms.common.ajax_post(js_param.fix_comment_submit_url,params,function(json){
                json = eval("("+json+")");
                if(json.type){
                    $.alert({
                        title  : language.note.alert_title,
                        message: json.msg,
                        fnOk   : function () {
                            fix_editor.html("");
                            $('#fix_txt_answner').text("");
                            form_msg.hide();
                            fix_comment_layer.close();
                            issue_list.toolbar_disabled_check();
                           issue_list.reload();
                        }
                    });
                }else{
                    form_msg.html("<span class='error_msg'>" + json.msg + "</span>");
                    form_msg.show();
                }
            });
        },
        /**
         * 关闭问题操作，如果id  为0，属于批量关闭
         * @param id
         */
        close                : function (id) {
            ids_post=(id==0?cdms.common.grid_select_ids(grid_id):id );
                close_comment_layer.open();
                if(editor == null){
                    editor = KindEditor.create('#close_txt_answner', {
                        themeType            : 'default',
                        resizeType           : 0,
                        urlType              : 'domain',
                        shadowMode           : false,
                        allowPreviewEmoticons: false,
                        allowImageUpload     : true,
                        allowFlashUpload     : false,
                        uploadJson           : js_param.upload_url,
                        afterCreate          : function () {
                            KindEditor.ctrl(this.edit.iframe.get(0).contentWindow.document, 13, function () {
                                $("#close_txt_answner").parent().submit();
                            });
                        },
                        afterChange          : function () {
                            this.sync();
                        },
                        items                : ['bold', 'italic', 'underline', 'strikethrough', 'removeformat', '|', 'insertorderedlist', 'insertunorderedlist',
                            'forecolor', 'hilitecolor', 'fontname', 'fontsize', '|', 'link', 'unlink', 'image', 'flash', 'quote', '|', 'source', 'about']
                    });
                }
        },

        /**多问题设置里程碑*/
        multiple_milestone:function(){
            ids_post = cdms.common.grid_select_ids(grid_id);
            issue_list.single_milestone(ids_post);
        },
        /**
         * 单个问题里程碑  设置
         */
        single_milestone:function(id){
            cdms.common.ajax_get(js_param.issue_get_milestones_url + project_id, function (milestones) {
                data= eval("("+milestones+")");
                var html = '<input id="to_milestone" type="hidden" /><input id="issue_id" type="hidden" value=' + id + ' />' +
                    '<table id="milestone_table" style="height: 80%;width: 100%;table-layout:fixed">';
                for (var i = 0; i < data.length; i++) {
                    html += '<tr style="height: 20px;margin: 2px;border: 2px solid;background-color: #F5F8FC;cursor: pointer" id="{0}" ><td onclick="issue_list.choose_milestone(\'{1}\')"><a href="javascipt:;" style="text-decoration: none;color: #85848f; font-size: 14px ">{2}</a></td></tr>'.format(data[i].id, data[i].id, data[i].name);
                }
                html += "<tr></tr></table>";
                html += "<button id='milestone' width='100%' style='float:left' onclick='issue_list.single_milestone_submit()'><span><span>{0}</span></span></button>".format(language.issue.issue_assing_confirm);
                html += "<button id='milestone' width='100%' style='float:right' onclick='issue_list.close_layer(\"{0}\")'><span><span>{1}</span></span></button>".format("single_milestone", language.common.cancel);

                single_milestone_layer_operation.attr("contents", html);
                single_milestone_layer_operation.open();

            });
        },
        /**里程碑选择*/
        choose_milestone:  function(milestone){
            $("#milestone_table").find("tr[id !='" + milestone + "']").css({backgroundColor: "#F5F8FC"});
            $("#" + milestone).css({backgroundColor: "#D0E5F6", textDecorationColor: "white"});
            $("#to_milestone").attr("value", milestone);
        },
        /**选择里程碑后，提交设置*/
        single_milestone_submit:  function(){
            var milestone = $("#to_milestone").attr("value");
            var issue_id = $("#issue_id").attr("value");
            if (milestone == "") {
                $.alert(language.issue.not_checked, language.note.alert_title);
                return false;
            }
            var param = {issue_id: issue_id, milestone: milestone};
            cdms.common.ajax_post(js_param.issue_set_milestones_url, param, function (json) {
                 json=eval("("+json+")");
                if (json.type) {
                    $.alert(json.msg, language.note.alert_title);
                }
                single_milestone_layer_operation.close();
                issue_list.reload();
            });
        },

        single_assign        : function (id) {
            cdms.common.ajax_get(js_param.view_issue_accounts_url + project_id, function (accounts) {
                var data = eval("("+accounts+")");
                var html = '<input id="assgin_to" type="hidden" /><input id="assgin_id" type="hidden" value=' + id + ' />' +
                    '<table id="assign_table" style="height: 80%;width: 100%;table-layout:fixed">';
                for (var i = 0; i < data.length; i++) {
                    html += '<tr style="height: 20px;margin: 2px;border: 2px solid;background-color: #F5F8FC;cursor: pointer" id="{0}" ><td onclick="issue_list._choose_assign(\'{1}\')"><a href="javascipt:;" style="text-decoration: none;color: #85848f; font-size: 14px ">{2}</a></td></tr>'.format(data[i].login, data[i].login, data[i].name);
                }
                html += "<tr></tr></table>";
                html += "<button id='assign' width='100%' style='float:left' onclick='issue_list.single_asssign_submit()'><span><span>{0}</span></span></button>".format(language.issue.issue_assing_confirm);
                html += "<button id='assign' width='100%' style='float:right' onclick='issue_list.close_layer(\"{0}\")'><span><span>{1}</span></span></button>".format("single_assign", language.common.cancel);

                single_assign_layer_operation.attr("contents", html);
                single_assign_layer_operation.open();

            });
        },
        _choose_assign       : function (assign) {
            $("#assign_table").find("tr[id !='" + assign + "']").css({backgroundColor: "#F5F8FC"});
            $("#" + assign).css({backgroundColor: "#D0E5F6", textDecorationColor: "white"});
            $("#assgin_to").attr("value", assign);
        },
        /**
         * 列表操作栏中的指派给操作
         * @return {boolean}
         */
        single_asssign_submit: function () {
            var assign_name = $("#assgin_to").attr("value");
            var assign_id = $("#assgin_id").attr("value");
            if (assign_name == "") {
                $.alert(language.issue.not_checked, language.note.alert_title);
                return false;
            }
            var param = {id: assign_id, name: assign_name};
            cdms.common.ajax_post(js_param.view_assign_submit, param, function (msg) {
                if (msg.type) {
                    $.alert(msg.msg, language.note.alert_title);
                    return;
                }
                single_assign_layer_operation.close();
                issue_list.reload();
            });
        },

        /**
         * Close layer
         */
        close_layer          : function (id) {
            $("#" + id).layer().close();
            if($("#close_txt_answner")!=null){
                $("#close_txt_answner").attr("value","");
            }
        },
        /**
         * multiply assign the question to account  多指派 功能
         */
        team_account         : function () {
              ids_post = cdms.common.grid_select_ids(grid_id);
             issue_list.single_assign(ids_post);
        },

        /**
         * refresh grid
         */
        reload               : function () {
            $('#' + grid_id).grid().loadData();
        },

        label_f_click        : function (dom_id) {
            var current = $('#' + dom_id);
            var linek = $('#' + dom_id + '_link');
            linek.addClass("selected");
            var value = current.attr("value");
            var color = current.attr("color");
            linek.css('background', color);
            var choose_label = $("#choose_label");
            choose_label.find("li[value!='" + value + "']").removeClass("selected");
            choose_label.find("a[value!='" + value + "']").removeAttr('style');
            var val_selct = $('#label_select_val');
            val_selct.val(value);
            val_selct.attr('name', current.attr('name'));
            val_selct.attr('color', color);
        },
        priopity_f_click     : function (dom_id) {
            var current = $('#' + dom_id);
            var linek = $('#' + dom_id + '_link');
            linek.addClass("selected");
            var value = current.attr("value");
            linek.addClass("linek");
            var choose_priopity = $("#choose_priopity");
            choose_priopity.find("li[value!='" + value + "']").removeClass("selected");
            choose_priopity.find("a[value!='" + value + "']").removeAttr('style');
            choose_priopity.find("a[value!='" + value + "']").removeClass("linek");
            var val_selct = $('#priopity_select_val');
            val_selct.val(value);
            val_selct.attr('name', current.attr('name'));
        },
        choose_label_close   : function () {
            $("#label_change_div").layer().close();
        },
        choose_close         : function () {
            $('#priopity_change_div_list').layer().close();
        },
        choose_ok            : function () {
            var val_selct = $('#label_select_val');
            var label = val_selct.val();
            if (!label) {
                $.alert(language.issue.chose_label_msg, language.note.alert_title);
                return;
            }

            var rows = $('#'+grid_id).grid("checkedRows");
            var ids="";
            if(currentId==0){
                if (rows.length == 0) {
                    $.alert(language.issue.not_checked, language.note.alert_title);
                    return;
                }
                else{
                    for (var i = 0; i < rows.length; i++) {
                        var rowData = rows[i].attr("data");
                        ids += rowData.id + ",";
                    }
                }
            }
            else{
                ids=currentId;
            }
            cdms.common.ajax_post(js_param.label_change_url, {ids: ids, lv: label}, function (data) {
                issue_list.reload();
                currentId=0;
                $("#label_change_div").layer().close();
            });
        },
        label_change_div : function(id){
            currentId = id;
            $("#label_change_div").layer({
                width : "160px",
                height : "210px",
                singleton: true
            }).open();
        },
        priopity_layer : function(id){
            currentId = id;
            $("#priopity_change_div_list").layer({
                width : "160px",
                height : "220px",
                singleton: true
            }).open();
        },
        priopity_choose_close: function () {
            $('#priopity_change_div_list').layer().close();
        },
        priopity_choose_ok   : function () {
            var val_selct = $('#priopity_select_val');
            var priopity = val_selct.val();
            if (!priopity) {
                $.alert(language.issue.chose_prioperty_msg, language.note.alert_title);
                return;
            }
//            var color = val_selct.attr('color');
//            var name = val_selct.attr('name');
            var rows = $('#'+grid_id).grid("checkedRows");
            var ids = "";
            if(currentId==0){
                if (rows.length == 0) {
                    $.alert(language.issue.not_checked, language.note.alert_title);
                    return;
                }
                else{
                    for (var i = 0; i < rows.length; i++) {
                        var rowData = rows[i].attr("data");
                        ids += rowData.id + ",";
                    }
                }
            }
            else{
                ids=currentId;
            }
            cdms.common.ajax_post(js_param.priopity_change_url, {ids: ids, priopity: priopity}, function (data) {
                issue_list.reload();
                $("#priopity_change_div_list").layer().close();
                currentId=0;
            });
        }
    }
}();


$(document).ready(function () {
    //初始化
    issue_list.init();

});

